home *** CD-ROM | disk | FTP | other *** search
/ Software Vault: The Gold Collection / Software Vault - The Gold Collection (American Databankers) (1993).ISO / cdr49 / 115_01.zip / ED8.C < prev    next >
Text File  |  1993-06-01  |  5KB  |  279 lines

  1. /* Screen editor:  operating system module
  2.  *
  3.  * Source:  ed8.c
  4.  * Version: June 19, 1981.
  5.  */
  6.  
  7. /* all calls to the operating system are made here.
  8.  * only this module and the assembler libraries will have to be
  9.  * rewritten for a new operating system.
  10.  */
  11.  
  12. /* the routines syscstat(), syscin() and syscout() come in
  13.  * two flavors:  CP/M version 2.2 and CP/M version 1.4.
  14.  * Comment out which ever you don't use.
  15.  */
  16.  
  17. /* CP/M 2.2 versions of syscstat(), syscin(), syscout() */
  18.  
  19. /* return -1 if no character is ready from the console. 
  20.  * otherwise, return the character.
  21.  */
  22.  
  23. syscstat()
  24. {
  25.     return(cpm(6,-1));
  26. }
  27.  
  28. /* wait for next character from the console.
  29.  * do not echo it.
  30.  */
  31.  
  32. syscin()
  33. {
  34. int c;
  35.     while ((c=cpm(6,-1))==0) {
  36.         ;
  37.     }
  38.     return(c);
  39. }
  40.  
  41. /* print character on the console */
  42.  
  43. syscout(c) char c;
  44. {
  45.     cpm(6,c);
  46.     return(c);
  47. }
  48.  
  49. /* CP/M 1.4 versions of syscstat(), syscin(), syscout() */
  50.  
  51. /* start comment out ----------
  52. #asm
  53. ;
  54. ;    bios(n,bc)
  55. ;
  56. ;    call the n'th bios routine.
  57. ;    bc is put into the bc-register as a parameter.
  58. ;    returns whatever bios puts into the a-reg.
  59. ;
  60. QZBIOS:
  61.     POP    H    ;get return address
  62.     POP    B    ;    bc
  63.     POP    D    ;    n
  64.     PUSH    D    ;restore stack the way it was
  65.     PUSH    B
  66.     PUSH    H
  67.     LHLD    1    ;point hl at start of BIOS jump table
  68.     DCX    H
  69.     DCX    H
  70.     DCX    H
  71.     MOV    A,E    ;put index into jump table into de
  72.     ADD    A
  73.     ADD    E
  74.     MVI    D,0
  75.     MOV    E,A
  76.     DAD    D    ;point hl at proper entry in jump table
  77.     PUSH    H    ;push call address
  78.     LXI    H,QZBIOS1 ;point hl at return address
  79.     XTHL        ;push return address, get call address
  80.     PCHL        ;call proper BIOS routine
  81. QZBIOS1:
  82.     MOV    L,A     ;put return code from BIOS into hl
  83.     MVI    H,0
  84.     RET        ;go back to small-c
  85. #endasm
  86.  
  87. syscstat()
  88. {
  89.     if (bios(2,0)==255) {
  90.         return(-1);
  91.     }
  92.     else {
  93.         return(0);
  94.     }
  95. }
  96.  
  97. syscin()
  98. {
  99.     return(bios(3,0));
  100. }
  101.  
  102. syscout(c) char c;
  103. {
  104.     bios(4,c);
  105.     return(c);
  106. }
  107. ---------- end comment out */
  108.  
  109.  
  110. /* print character on the printer */
  111.  
  112. syslout(c) char c;
  113. {
  114.     cpm(5,c);
  115.     return(c);
  116. }
  117.  
  118. #asm
  119. ;
  120. ; sysend()
  121. ;
  122. ; return address of last usable memory location.
  123. ;
  124. QZSYSEND:
  125.     LHLD    6    ;get address of BDOS-1
  126.     DCX    H    ;
  127.     RET        ;return
  128. #endasm
  129.  
  130. /* open a file */
  131.  
  132. sysopen(name,mode) char *name, *mode;
  133. {
  134. int file;
  135.     if ((file=fopen(name,mode))==0) {
  136.         return(ERR);
  137.     }
  138.     else {
  139.         return(file);
  140.     }
  141. }
  142.  
  143. /* close a file */
  144.  
  145. sysclose(file) int file;
  146. {
  147.     /* fclose doesn't reliably return OK */
  148.     fclose(file);
  149.     return(OK);
  150. }
  151.  
  152. /* read next char from file */
  153.  
  154. sysrdch(file) int file;
  155. {
  156. int c;
  157.     if ((c=getc(file))==-1) {
  158.         return(EOF);
  159.     }
  160.     else {
  161.         return(c);
  162.     }
  163. }
  164.  
  165. /* write next char to file */
  166.  
  167. syspshch(c,file) char c; int file;
  168. {
  169.     if (putc(c,file)==-1) {
  170.         error("disk write failed");
  171.         return(ERR);
  172.     }
  173.     else {
  174.         return(c);
  175.     }
  176. }
  177.  
  178. /* read one char from END of file */
  179.  
  180. syspopch(file) int file;
  181. {
  182.     error("syspopch() not implemented");
  183.     return(ERR);
  184. }
  185.  
  186. /* check file name for syntax */
  187.  
  188. syschkfn(args) char *args;
  189. {
  190.     return(OK);
  191. }
  192.  
  193. /* copy file name from args to buffer */
  194.  
  195. syscopfn(args,buffer) char *args, *buffer;
  196. {
  197. int n;
  198.     n=0;
  199.     while (n< SYSFNMAX-1) {
  200.         if (args[n]==EOS) {
  201.             break;
  202.         }
  203.         else {
  204.             buffer[n]=args[n];
  205.             n++;
  206.         }
  207.     }
  208.     buffer[n]=EOS;
  209. }
  210.  
  211. /* move a block of n bytes down (towards HIGH addresses).
  212.  * block starts a source and the first byte goes to dest.
  213.  * this routine is only called from bufmovdn() as follows
  214.  *    sysmovdn( n=to-from+1, dest=to+length, source=to);
  215.  */
  216.  
  217. #asm
  218. QZSYSMOVDN:
  219.     POP    H    ;get return address
  220.     POP    B    ;BC = source
  221.     POP    D    ;DE = dest
  222.     XTHL        ;HL = n, restore return address
  223.     JMP    SYSMOVDN2    ;go enter loop
  224. ;
  225. ; this code is 15 times faster than the c-code it replaces.
  226. SYSMOVDN1:
  227.     LDAX    B    ;*dest-- = *source--
  228.     STAX    D
  229.     DCX    B
  230.     DCX    D
  231.     DCX    H    ;while ((n--)>0)
  232. SYSMOVDN2:
  233.     MOV    A,L
  234.     ORA    H
  235.     JNZ    SYSMOVDN1
  236. ;
  237.     XTHL        ;HL = return address
  238.     PUSH    H    ;restore stack
  239.     PUSH    H
  240.     PUSH    H
  241.     RET        ;return
  242. #endasm
  243.  
  244. /* move a block of n bytes up (towards LOW addresses).
  245.  * the block starts at source and the first byte goes to dest.
  246.  * this routine is called only from bufmovup() as follows:
  247.  *     sysmovup( n=to-from+1, dest=from-length, source=from);
  248.  */
  249.  
  250. #asm
  251. QZSYSMOVUP:
  252.     POP    H    ;get return address
  253.     POP    B    ;BC = source
  254.     POP    D    ;DE = dest
  255.     XTHL        ;HL = n, save return address
  256.     JMP    SYSMOVUP2    ;go enter loop
  257. ;
  258. ; this code is 15 times faster than the c-code it replaces.
  259. SYSMOVUP1:
  260.     LDAX    B    ;*dest++ = *source++
  261.     STAX    D
  262.     INX    B
  263.     INX    D
  264.     DCX    H    ;while ((n--)>0)
  265. SYSMOVUP2:
  266.     MOV    A,L
  267.     ORA    H
  268.     JNZ    SYSMOVUP1
  269. ;
  270.     XTHL        ;HL = return address
  271.     PUSH    H    ;restore stack
  272.     PUSH    H
  273.     PUSH    H
  274.     RET        ;return
  275. #endasm
  276.  
  277.     ;go enter loop
  278. ;
  279. ; this code is 15 times faster than the c-code it